<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentFriendsList.class.php, $Author:  $ */



/** Display long list of friends
 *
 * Parameters:
 *  1. oUser (mandatory) - user account object
 *
 * @package module.account
 * @version $Id: PhpFox_ComponentFriendsList.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *
 */
class PhpFox_Mod_Account_ComponentFriendsList extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    $oAcc = $this->getParam('oUser');
	    assert(null != $oAcc);

	    $oReq = &App::getRequest();
	    $sMode = "short";

		$oSrvFriends = $this->_oModule->getService('Friends');
		/* @var $oSrvFriends PhpFox_Mod_Account_ServiceFriends */

	    switch($oReq->getAction())
	    {

	        // --- change view mode ---
	        case 'change_mode':
		        $oUrl = &App::getUrl();
		        $oUrl->setParam('mode', $sMode);
		        App::forward($oUrl->getUrl());
	            break;

	        // --- delete friend ---
	        case 'delete_friend':
	            $oSrvFriends->deleteFriend($oAcc, $oReq->get('user'));
		        $oUrl = &App::getUrl();
		        $oUrl->clearParams('act');
		        $oUrl->clearParams('id');
		        App::forward($oUrl->getUrl());
	            break;

	        // --- make/unmake top friend ---
	        case 'make_top':
	        case 'unmake_top':

	        	if ( $oReq->getAction() == 'make_top' AND $iCntTop = $oSrvFriends->reachedTopLimit($oAcc) AND $iCntTop >= App::getParam('public.top.friends') )
	        	{
	        		$sLimit = $iCntTop;
	        	}
	        	else
	        	{
	            	$bIsTop = ('make_top' == $oReq->getAction());
	            	$oSrvFriends->setTopFriend($oAcc, $oReq->get('user'), $bIsTop);
	            	$oUrl = &App::getUrl();
		        	$oUrl->clearParams('act');
		        	$oUrl->clearParams('name');
		        	App::forward($oUrl->getUrl());
		        }
	            break;
	    }

		$iPage = $oReq->getInt('page', 1);
    	$iPagesize = App::getParam('public.pagesize');

		list($aFriends, $iTotal) = $oSrvFriends->getFriendList($oAcc, $iPage, $iPagesize, 'time', true);
		$aFriendsTop = $oSrvFriends->getFriendListTop($oAcc);

    	$oPager = App::newObject('Pager', $iTotal, $iPage, $iPagesize);

	    $oSrvAcc = &$this->_oModule->getService('Account');
	    /* @var $oSrvAcc PhpFox_Mod_Account_ServiceAccount */

        $oTpl = &$this->_oModule->getTemplate();

        $oTpl->assign(array(
	        'sMode'       => $sMode,
			'sUserPicUrl' => App::getParam('user.pic.url'),
			 'aFriends'    => $aFriends,
	        'aPaging'     => $oPager->getInfo(App::getUrl()),
            'iRowSize'    => $this->getParam('iRowSize', 3),
            'aTop' => $aFriendsTop,
            'sLimit' => isset($sLimit) ? $sLimit : '',
        ));

        $sTemplate = $this->getParam('sTemplate', 'FriendsList');
		$srcHtml = $oTpl->fetch($sTemplate.'.html');
		return $srcHtml;
	}

}
?>